﻿@{
    Layout = "~/Views/Shared/_AddEdit.cshtml";
}
@section header{
    <script type="text/javascript">
        function SaveBeforeCallBack() {
            if ($("#htsl").val() > 0) {
                layer.msg('温馨提示：已有合同，请重新输入~！~'); return true;
            }
            if ($("#_contractNumber").val() == '' || $("#_contractNumber").val() == null ) {
                layer.msg('温馨提示：必须选择填写合同编号~！~'); return true;
            }
            if ($("#_Cid").val() == '' || $("#_Cid").val() == null || $("#_Cid").val() == "-1") {
                layer.msg('温馨提示：必须选择客户~！~'); return true;
            }
            if ($("#_SetmealId") == '' || $("#_SetmealId") == null) {
                layer.msg('温馨提示：必须选择合同套餐~！~'); return true;
            }
            if ($("#_DisPrice").val() == '' || $("#_DisPrice").val()==null) {
                layer.msg('温馨提示：必须输入金额~！~'); return true;
            }

            $("#_CreateDate").val("@System.DateTime.Now");
        }


    </script>
}
<input type="hidden" name="_ConCourseNumber" id="_ConCourseNumber" value="@ViewBag.data["ConCourseNumber"]" />
<input type="hidden" name="_SetmealName" id="_SetmealName" value="@ViewBag.data["SetmealName"]" />
<input type="hidden" name="_ContractPrice" id="_ContractPrice" value="@ViewBag.data["ContractPrice"]" />
<input type="hidden" name="_SurplusNumber" id="_SurplusNumber" value="@ViewBag.data["SurplusNumber"]" />
<input type="hidden" name="_MaxLeave" id="_MaxLeave" value="@ViewBag.data["MaxLeave"]" />
<input type="hidden" name="_Gift1Price" id="_Gift1Price" value="@ViewBag.data["Gift1Price"]" />
<input type="hidden" name="_Gift2Price" id="_Gift2Price" value="@ViewBag.data["Gift2Price"]" />
<input type="hidden" name="_Gift3Price" id="_Gift3Price" value="@ViewBag.data["Gift3Price"]" />
<input type="hidden" name="_MaxMakeUP" id="_MaxMakeUP" value="@ViewBag.data["MaxMakeUP"]" />
<input type="hidden" name="_Cid" id="_Cid" value="@ViewBag.data["Cid"]" />
<input type="hidden" name="_LinkCustId" id="_LinkCustId" />
<input type="hidden" name="_ImageUrl" id="_ImageUrl" />
<input type="hidden" name="_ImageName" id="_ImageName" />
<input type="hidden" name="htsl" id="htsl" />
<input type="hidden" name="_guid" id="_guid" value="@ViewBag.data["guid"]" />
<input type="hidden" name="_state" id="_state" value="@ViewBag.data["state"]" />
<input type="hidden" name="_status" id="_status" value="@ViewBag.data["status"]" />

<input type="hidden" name="_CreateId" id="_CreateId" value="@ViewBag.data["CreateId"]" />
<input type="hidden" name="_CreateDate" id="_CreateDate" value="@ViewBag.data["CreateDate"]" />
<input type="hidden" name="_AchievementId" id="_AchievementId" value="@ViewBag.data["AchievementId"]" />
<input type="hidden" name="_LeagueId" id="_LeagueId" value="@ViewBag.data["LeagueId"]" />
<div class="layui-card-body">

    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-row layui-col-space1" style="min-width:1600px;">
            <div class="layui-col-md6" style="min-width:800px;">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">合同编号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="_contractNumber" id="_contractNumber" value="@ViewBag.data["contractNumber"]" lay-verify="title" autocomplete="off" placeholder="合同编号" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">会员卡号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="_CardNumber" value="@ViewBag.data["CardNumber"]" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    @if (ViewBag.Lx == 1)
                    {

                        <label class="layui-form-label">人员信息</label> <span id="Khry"></span><a class="layui-btn" href="#" onclick="AddUser()"><i class="layui-icon">&#xe613;</i></a>
                    }
                    else if (@ViewBag.Customer == 0)
                    { <label class="layui-form-label">人员选择</label>
                        <div class="layui-input-inline">
                            <input type="text" id="CusDisplay" placeholder="请输入手机号码进行查询" class="layui-input">
                        </div><a class="layui-btn" href="#" onclick="searchCus()"><i class="layui-icon">&#xe615;</i></a>
                        <a class="layui-btn" href="#" onclick="AddUser()"><i class="layui-icon">&#xe613;</i></a>
                    }
                </div>
                <div class="layui-form-item" id="xyselect" style="display:none;">

                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">合同类型</label>
                    <div class="layui-input-block">
                        <input type="radio" name="_contracttype" lay-filter="contracttype" value="新签约" title="新签约" @(ViewBag.data["contracttype"] == "新签约" ? "checked='checked'" : "")>
                        <input type="radio" name="_contracttype" lay-filter="contracttype" value="续签" title="续签" @(ViewBag.data["contracttype"] == "续签" ? "checked='checked'" : "")>
                        <input type="radio" name="_contracttype" lay-filter="contracttype" value="赠送" title="赠送" @(ViewBag.data["contracttype"] == "赠送" ? "checked='checked'" : "")>
                        <input type="radio" name="_contracttype" lay-filter="contracttype" value="升课包" title="升课包" @(ViewBag.data["contracttype"] == "升课包" ? "checked='checked'" : "")>
                    </div>
                </div>
                <div class="layui-form-item">

                    <label class="layui-form-label">合同套餐</label>
                    <div class="layui-input-inline">
                        <select lay-verify="required" name="_SetmealId" lay-filter="SetmealId" id="_SetmealId">
                            <option value=""></option>
                            @foreach (var data in ViewBag.SetmealType.Rows)
                            {

                                <option value="@data["id"]" @(ViewBag.data["SetmealId"] == @data["id"] ? "selected" : "")>@data["ContName"]</option>
                            }

                        </select>

                    </div>
                    <div class="layui-form-mid layui-word-aux" id="HdxxDisp"></div>


                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">实收金额</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="_DisPrice" id="_DisPrice" value="@ViewBag.data["DisPrice"]" lay-verify="required|number" lay-filter="DisPrice" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">赠送课时</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="_GiveCourseNumber" value="@ViewBag.data["GiveCourseNumber"]" lay-verify="required|number" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">签约日期</label>
                        <div class="layui-input-block" style="width: 120px;">
                            <input type="text" name="_ContractDate" value="@ViewBag.data["ContractDate"]" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input test-laydate-item">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline ">
                        <label class="layui-form-label">起止日期</label>
                        <div class="layui-input-inline" style="width: 120px;">
                            <input type="text" name="_Constart" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input test-laydate-item">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline" style="width: 120px;">
                            <input type="text" name="_ConEnd" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input test-laydate-item">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">付款方式</label>
                        <a class="layui-btn " href="#" onclick="Add()"><i class="layui-icon">&#xe654;</i></a>
                    </div>
                </div>
                <div>

                </div>
                <div class="layui-form-item">
                    <table style="margin-left:30px;">
                        <tr>
                            <td>赠送礼物1</td>
                            <td>
                                <div class="layui-input-inline">
                                    <select lay-verify="required" name="_Gift1" lay-filter="Gift1" id="_Gift1">
                                        <option value=""></option>
                                        @foreach (var data in ViewBag.Gift.Rows)
                                        {

                                            <option title="@data["helpcode"]" value="@data["dname"]" @if (ViewBag.data["Gift1"] is System.DBNull) { } else { @(ViewBag.data["Gift1"] == @data["dname"] ? "selected" : "") }>@data["dname"]</option>
                                        }

                                    </select>

                                </div>
                            </td>
                            <td> <span id="_Gift1Disp">@ViewBag.data["Gift1Price"]</span></td>
                            <td rowspan="3">
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">备注</label>
                                    <div class="layui-input-block">
                                        <textarea name="_Remark" placeholder="请输入内容" class="layui-textarea" style="min-height:150px;min-width:250px;">@ViewBag.data["Remark"]</textarea>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>赠送礼物2</td>
                            <td>
                                <div class="layui-input-inline">
                                    <select lay-verify="required" name="_Gift2" lay-filter="Gift2" id="_Gift2">
                                        <option value=""></option>
                                        @foreach (var data in ViewBag.Gift.Rows)
                                        {

                                            <option title="@data["helpcode"]" value="@data["dname"]" @if (ViewBag.data["Gift2"] is System.DBNull) { } else { @(ViewBag.data["Gift2"] == @data["dname"] ? "selected" : "") }>@data["dname"]</option>
                                        }

                                    </select>

                                </div>
                            </td>
                            <td><span id="_Gift2Disp">@ViewBag.data["Gift2Price"]</span></td>
                        </tr>
                        <tr>
                            <td>赠送礼物3</td>
                            <td>
                                <div class="layui-input-inline">
                                    <select lay-verify="required" name="_Gift3" lay-filter="Gift3" id="_Gift3">
                                        <option value=""></option>
                                        @foreach (var data in ViewBag.Gift.Rows)
                                        {

                                            <option title="@data["helpcode"]" value="@data["dname"]" @if (ViewBag.data["Gift3"] is System.DBNull) { } else { @(ViewBag.data["Gift3"] == @data["dname"] ? "selected" : "") }>@data["dname"]</option>
                                        }

                                    </select>

                                </div>
                            </td>
                            <td><span id="_Gift3Disp">@ViewBag.data["Gift3Price"]</span></td>
                        </tr>
                    </table>
                </div>
                <div class="layui-form-item" style="margin-left:30px;">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="testList">选择合同附件</button>
                        <div class="layui-upload-list">
                            <table class="layui-table" lay-filter="Imagetable" id="Imagetable">
                                <thead>
                                <th>文件名</th>
                                <th>大小</th>
                                <th>状态</th>
                                <th>操作</th>
                                </thead>
                                <tbody id="demoList"></tbody>
                            </table>
                        </div>
                        <button type="button" class="layui-btn" id="testListAction">开始上传</button>
                    </div>
                </div>

            </div>
            <div class="layui-col-md6">
                @if (ViewBag.Lx == 1)
                {
                    <div class="layui-card" id="Khxx" style="display:none;">
                        <fieldset class="layui-elem-field layui-field-title">
                            <legend>合同信息</legend>
                        </fieldset>
                        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                            <ul class="layui-tab-title">
                                <li class="layui-this">排课信息</li>
                                <li>收费明细</li>
                                <li>合同明细</li>
                                <li>活动明细</li>
                                <li>合同附件</li>
                                <li>关系 人</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <table class="layui-table" lay-skin="line" lay-filter="Pkxxtable" id="Pkxxtable"></table>
                                </div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Rydjtable" id="Rydjtable"></table></div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Ryhttable" id="Ryhttable"></table></div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Ryhdtable" id="Ryhdtable"></table></div>

                                <div class="layui-tab-item">

                                    <div class="layui-fluid" id="ImageFj"></div>

                                </div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Linktable" id="Linktable"></table></div>
                            </div>
                        </div>

                    </div>
                }
                else
                {
                    <div class="layui-card" id="Khxx" style="display:none;">
                        <fieldset class="layui-elem-field layui-field-title">
                            <legend>客户信息</legend>
                        </fieldset>
                        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                            <ul class="layui-tab-title">
                                <li class="layui-this">客户摘要</li>
                                <li>收费明细</li>
                                <li>合同明细</li>
                                <li>活动明细</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <div id="xy">
                                        <table class="layui-table" style="width:700px;">
                                            <tbody>
                                                <tr>
                                                    <td>信息</td>
                                                    <td>
                                                        <div id="BB"></div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>订金</td>
                                                    <td>
                                                        <div id="Djzy"></div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>合同</td>
                                                    <td>    <div id="Htzy"></div></td>
                                                </tr>
                                                <tr>
                                                    <td>活动</td>
                                                    <td>
                                                        <div id="Hdzy"></div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>动态</td>
                                                    <td style="padding-bottom: 0;">
                                                        <div id="dt"></div>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Rydjtable" id="Rydjtable"></table></div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Ryhttable" id="Ryhttable"></table></div>
                                <div class="layui-tab-item"><table class="layui-table" lay-skin="line" lay-filter="Ryhdtable" id="Ryhdtable"></table></div>

                            </div>
                        </div>

                    </div>}

            </div>
        </div>

    </form>

</div>

<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script>
    $(document).ready(function () {
        $("#_contractNumber").blur(function () { IsContractNumber(this.value);})
    });

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        lay('.test-laydate-item').each(function () {
            laydate.render({
                elem: this
                , trigger: 'click'
                , value: new Date()
            });
        });


    });

    layui.use('form', function () {
        var form = layui.form;

        form.on('select(Gift1)', function (data) {
            $('#_Gift1Price').val(data.elem[data.elem.selectedIndex].title);
            $('#_Gift1Disp').html(data.elem[data.elem.selectedIndex].title);
        });
        form.on('select(Gift2)', function (data) {
            $('#_Gift2Price').val(data.elem[data.elem.selectedIndex].title);
            $('#_Gift2Disp').html(data.elem[data.elem.selectedIndex].title);
        });
        form.on('select(Gift3)', function (data) {
            $('#_Gift3Price').val(data.elem[data.elem.selectedIndex].title);
            $('#_Gift3Disp').html(data.elem[data.elem.selectedIndex].title);
        });

        form.on('select(SetmealId)', function (data) {




                  $.ajax({
                      url: "../Contract/ContractList/SetmealType",
                dataType: "json",
                data: {
                    type: "@ViewBag.type",
                    id: "@ViewBag.id",
                    keyCode: data.value,
                    t: new Date().getTime()
                },
                success: function (data) {

                    if (data.code = "0000") {
                        $('#_SetmealName').val(data.data[0].ContName);
                        $('#_DisPrice').val(data.data[0].Price);
                        $('#_ContractPrice').val(data.data[0].Price);
                        $('#_ConCourseNumber').val(data.data[0].number);
                        $('#_SurplusNumber').val(data.data[0].number);
                        $('#_MaxLeave').val(data.data[0].MaxLeave);
                        $('#_MaxMakeUP').val(data.data[0].MaxMakeUP);
                        $('#HdxxDisp').html('金额：' + data.data[0].Price + ' 课时或时长： ' + data.data[0].number + '可请假：' + data.data[0].MaxLeave + '可补课：' + data.data[0].MaxMakeUP);

                    }
                }


            });

        });
    })

    layui.use('upload', function () {
        var upload = layui.upload;

        ///多文件列表示例
        var demoListView = $('#demoList')
            , uploadListIns = upload.render({
                elem: '#testList'
                , url: '../Contract/ContractList/Upload?DirName=contract'
                , accept: 'file'
                , multiple: true
                , auto: false
                , bindAction: '#testListAction'
                , choose: function (obj) {
                    var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                    //读取本地文件
                    obj.preview(function (index, file, result) {
                        var tr = $(['<tr id="upload-' + index + '">'
                            , '<td>' + file.name + '</td>'
                            , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                            , '<td>等待上传</td>'
                            , '<td>'
                            , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                            , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                            , '</td>'
                            , '</tr>'].join(''));

                        //单个重传
                        tr.find('.demo-reload').on('click', function () {
                            obj.upload(index, file);
                        });

                        //删除
                        tr.find('.demo-delete').on('click', function () {
                            delete files[index]; //删除对应的文件
                            tr.remove();
                            uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                        });

                        demoListView.append(tr);
                    });
                }
                , done: function (res, index, upload) {
                    if (res.code == 0) { //上传成功
                        var tr = demoListView.find('tr#upload-' + index)
                            , tds = tr.children();
                        tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                        tds.eq(3).html(''); //清空操作

                        if ($("#_ImageUrl").val() == "") {
                            $("#_ImageUrl").val(res.data.src);
                            $("#_ImageName").val(tds.eq(0).html());
                        }
                        else {
                            $("#_ImageUrl").val($("#_ImageUrl").val() + ',' + res.data.src);
                            $("#_ImageName").val($("#_ImageName").val() + ',' + tds.eq(0).html());
                        }
                        return delete this.files[index]; //删除文件队列已经上传成功的文件
                    }
                    this.error(index, upload);
                }
                , error: function (index, upload) {
                    var tr = demoListView.find('tr#upload-' + index)
                        , tds = tr.children();
                    tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                    tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
                }
            });
    });


      function AddUser()
    {
          var index = layui.layer.open({
                            type: 2,
              content: '../Contract/LinkList?id=-1&cid=' + $("#_Cid").val() + '&keyCode= "@ViewBag.KeyCode"',
                            title: '添加关系人',
                            area: ['650px','650px'],
                            maxmin: false
                        });
    }
    function Add()
    {
        if ($("#_Cid").val() == "") { layer.msg('温馨提示：必须先选择客户~！~'); return true;}

        layer.open({
                            type: 2,
              content: '../Account/At?id=-1&cid=' + $("#_Cid").val() + '&FlowingType=00102001&guid=@ViewBag.data["guid"]&keyCode= @ViewBag.KeyCode',
                            title: '添加付款内容',
                            area: ['650px','650px'],
              maxmin: false,
              success: function (layero, index) {
                  var body = layer.getChildFrame('body', index);
                  var je = $('#_DisPrice').val() - body.find('#htysje').val();
                  body.find('#_Account').val(je);
            },
            end: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var dtnr = body.find('#_Remark').val();

                $("#dt").html(dtnr);
            }
        });

    }
    function HideModal(id) {

        layui.layer.closeAll();
    }

    function searchCus() {
        var indexs;
          if (@ViewBag.Lx== 0&&@ViewBag.Customer==0)
          indexs = layer.load();
        var UrlCs = "../Account/At/Data";
        var UrlValue = $("#CusDisplay").val();
        var column = [[{ field: 'id', title: 'ID', width: 60, sort: true }, { field: 'CustName', title: '宝宝姓名', width: 100 }, { field: 'ChildName', title: '小名', Width: 80 }, { field: 'LinkName', title: '联系人', Width: 80 }, { field: 'CustTel', title: '联系电话', minwidth: 100 }, { field: 'LinkRelation', title: '关系', width: 80 }]];

      $.ajax({
          url: UrlCs,
        dataType:"json",
        data: {
            type:"@ViewBag.type",
            id:"@ViewBag.id",
            keyCode: "@ViewBag.KeyCode",
            Tel: UrlValue,
              Khid:@ViewBag.Customer,
            t:new Date().getTime()
        },
          success: function (data) {
                 if (@ViewBag.Lx== 0&&@ViewBag.Customer==0)
              layer.close(indexs);
            if (data.code == "0000") {
                var json = eval(data.data); //数组
                if (json.length == 1) {
                    $("#Khxx").css('display', '');
                    $("#_AchievementId").val(json[0].LatelyReceId);
                    $("#_Cid").val(json[0].id);
                    if (json[0].Sex == "男")
                        $("#BB").html("<i class=\"layui-icon layui-icon-male\" style=\"color:bule;\"></i>宝宝姓名：" + json[0].CustName + " 宝宝小名：" + json[0].ChildName + " 联系人：" + json[0].LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + json[0].CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + json[0].UserName + "</span>");
                   else
                       $("#BB").html("<i class=\"layui-icon layui-icon-male\"  style=\"color:#FF69B4;\"></i>宝宝姓名：" + json[0].CustName + " 宝宝小名：" + json[0].ChildName + " 联系人：" + json[0].LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + json[0].CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + json[0].UserName + "</span>");
                    $("#Djzy").html("订金金额：" + json[0].Djje + " 其中未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].DjWrzJe + "</span> 已入账：" + json[0].DjWsyJe + " 已使用：" + json[0].DjYsyJe + " 已作废：" + json[0].DjZfJe);
                    $("#Htzy").html("合同金额：" + json[0].Htje + " 合同实收：" + json[0].HtSsje + " 其中未计费：<span class=\"layui-badge \" >" + json[0].HtWjfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].HtWrzJe + "</span> 已入账：" + json[0].HtRzJe + " 已退费：" + json[0].HtTfJe);
                    $("#Hdzy").html("参加活动次数：" + json[0].Hdsl + "  金额：" + json[0].Hdje + " 其中未收费：<span class=\"layui-badge \" >" + json[0].HdWsfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + json[0].HdWrzJe + "</span> 已入账：" + json[0].HdYrzJe + " 已退费：" + json[0].HdTfJe);
                    GetTable(json[0].id);
                    $("#xyselect").css('display', 'none');

                }
                else if (json.length > 1) {

                    $("#xyselect").css('display', '');
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.open({
                            title: '请选择人员信息',
                            type: 1,
                            shadeClose: true,
                            area: ['700px', '500px'],
                            content: $("#xyselect").html("<table class=\"layui - table\" lay-skin=\"line\" lay-filter=\"demo\" id=\"demo\"></table>"),
                            cancel: function (index, layero) { $("#xyselect").html(''); },
                            end: function (index, layero) { $("#xyselect").html(''); }
                        });
                    })
                    layui.use('table', function () {
                     var table = layui.table;
                    table.render({
                        elem: '#demo'
                        , cols: column
                        , data: data.data
                       ,skin: 'line' //表格风格
                        , even: true
                        ,page: true //是否显示分页

                        , limit: 10//每页默认显示的数量

                        });
                        table.on('row(demo)', function (obj) {

                            var data = obj.data;
                            $("#Khxx").css('display', '');
                            $("#_AchievementId").val(data.LatelyReceId);
                            $("#_Cid").val(data.id);

                             if (data.Sex == "男")
                                    $("#BB").html("<i class=\"layui-icon layui-icon-male\" style=\"color:bule;\"></i>宝宝姓名：" + data.CustName + " 宝宝小名：" + data.ChildName + " 联系人：" + data.LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + data.CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + data.UserName + "</span>");
                             else
                                    $("#BB").html("<i class=\"layui-icon layui-icon-male\"  style=\"color:#FF69B4;\"></i>宝宝姓名：" + data.CustName + " 宝宝小名：" + data.ChildName + " 联系人：" + data.LinkName + " 联系电话：<span class=\"layui-badge layui-bg-orange \" >" + data.CustTel + "</span> 业绩所属：<span class=\"layui-badge layui-bg-green \" >" + data.UserName + "</span>");
                              $("#Djzy").html("订金金额：" + data.Djje + " 其中未入账：<span class=\"layui-badge layui-bg-orange \" >" + data.DjWrzJe + "</span> 已入账：" + data.DjWsyJe + " 已使用：" + data.DjYsyJe + " 已作废：" + data.DjZfJe);
                              $("#Htzy").html("合同金额：" + data.Htje + " 合同实收：" + data.HtSsje + " 其中未计费：<span class=\"layui-badge \" >" + data.HtWjfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + data.HtWrzJe + "</span> 已入账：" + data.HtRzJe + " 已退费：" + data.HtTfJe);
                              $("#Hdzy").html("参加活动次数：" + data.Hdsl + "  金额：" + data.Hdje + " 其中未收费：<span class=\"layui-badge \" >" + data.HdWsfJe + "</span> 未入账：<span class=\"layui-badge layui-bg-orange \" >" + data.HdWrzJe + "</span> 已入账：" + data.HdYrzJe + " 已退费：" + data.HdTfJe);

                              GetTable(data.id);

                              layer.closeAll();
                            $("#xyselect").html('');
                        });

                    });
                }
                else {
                    $("#xy").html("未找到学员信息");
                    $("#_Cid").val("");
                    $("#_AchievementId").val("");
                    $("#xyselect").css('display', 'none');
                }

            }

        }
    });
    }
    function GetHtTable(id, ContractId) {

        var djUrl = "../Contract/ContractList/DjData";
        var CourseUrl = "../Contract/ContractList/CourseList";
        var HtUrl = "../Contract/ContractList/RyHtData";
        var HdUrl = "../Contract/ContractList/RyHdData";
        var LinkUrl = "../Contract/ContractList/LinkList";
                    layui.use('table', function () {
                        var table = layui.table;
                                 table.render({
                              elem: '#Pkxxtable'
                              , url: CourseUrl //数据接口
                            , where: { keyCode: "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id", Cid: id, ContractId: ContractId, t: new Date().getTime() }
                            , width: 780
                            , limit:5
                            , page: true //是否显示分页
                            , parseData: function (res) {
                                return {
                                    "code": res.code,
                                    "msg": res.message,
                                    "count": res.data.count,
                                    "data": res.data.data
                                };
                            }
                            , totalRow: true

                            , cols: [[ //标题栏
                                { field: 'Gordate', title: '签到时间', width: 120, totalRowText: '合计' }
                                , { field: 'CourseName', title: '课程', Width:150 }
                                , { field: 'DecClass', title: '扣课时', Width: 80, totalRow: true }
                                , { field: 'IsAuditions', title: '类型', width: 80 }
                                , { field: 'contractName', title: '合同名称', width: 120 }
                                , { field: 'surNumber', title: '剩余课时', width: 100 }
                                , { field: 'stateName', title: '状态', width:80 }
                            ]]

                            , skin: 'line' //表格风格
                            , even: true

                        });
                        table.render({
                            elem: '#Rydjtable'
                            , url: djUrl //数据接口
                            , where: { keyCode: "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id", Cid: id, ContractId: ContractId, t: new Date().getTime() }
                            , width: 780
                            , limit:5
                            , page: true //是否显示分页
                            , parseData: function (res) {
                                return {
                                    "code": res.code,
                                    "msg": res.message,
                                    "count": res.data.count,
                                    "data": res.data.data
                                };
                            }
                            , totalRow: true

                            , cols: [[ //标题栏
                                { field: 'FlowingName', title: '渠道', width: 80, totalRowText: '合计' }
                                , { field: 'SetmealName', title: '所属合同', Width:150 }
                                , { field: 'Account', title: '金额', Width: 60, totalRow: true }
                                , { field: 'ADate', title: '操作日期', width: 130 }
                                , { field: 'AchName', title: '业绩所属', width: 120 }
                                , { field: 'stateName', title: '状态', width: 80 }
                            ]]

                            , skin: 'line' //表格风格
                            , even: true

                        });

                          table.render({
                              elem: '#Linktable'
                              , url: LinkUrl //数据接口
                            , where: { keyCode: "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id", Cid: id, ContractId: ContractId, t: new Date().getTime() }
                            , width: 670
                            , limit:5
                            , page: true //是否显示分页
                            , parseData: function (res) {
                                return {
                                    "code": res.code,
                                    "msg": res.message,
                                    "count": res.data.count,
                                    "data": res.data.data
                                };
                            }


                              , cols: [[ //标题栏
                                  { field: 'id', title: '', width: 40 }
                               ,{ field: 'Gordate', title: '姓名', width: 120  }
                                , { field: 'CourseName', title: '小名', Width:120 }
                                , { field: 'DecClass', title: '性别', Width: 80  }
                                , { field: 'IsAuditions', title: '联系电话', width: 120 }
                                , { field: '', title: '操作', width: 120, toolbar: '#barDemo' }

                            ]]

                            , skin: 'line' //表格风格
                            , even: true

                        });
                         table.render({
                             elem: '#Ryhttable'
                            , url: HtUrl //数据接口
                            , where: { keyCode: "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id",Cid:id, t: new Date().getTime() }
                             , width:1050
                             , totalRow: true
                             , parseData: function (res) {
                                 return {
                                     "code": res.code,
                                     "msg": res.message,
                                     "count": res.data.count,
                                     "data": res.data.data
                                 };
                             }
                            , cols: [[ //标题栏
                                { field: 'contractNumber', title: '合同编号' }
                                , { field: 'SetmealName', title: '套餐名称' }
                                , { field: 'je', title: '已收/实收/金额', width: 190 }
                                , { field: 'ConDate', title: '合同日期', width: 190 }
                                , { field: 'CourseDate', title: '执行日期' }
                                , { field: 'CreateDate', title: '创建日期', width: 110 }
                                , { field: 'AchName', title: '业绩所属' }
                                , { field: 'stateName', title: '合同状态' }
                                , { field: 'stateName', title: '收费状态' }
                            ]]

                            , skin: 'line' //表格风格
                            , even: true
                            , page: true //是否显示分页

                            , limit: 5//每页默认显示的数量

                        });

                        table.render({
                             elem: '#Ryhdtable'
                            , url: HdUrl //数据接口
                            , where: { keyCode:  "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id",Cid:id, t: new Date().getTime() }
                            , width: 430
                            , totalRow: true
                            , parseData: function (res) {
                                return {
                                    "code": res.code,
                                    "msg": res.message,
                                    "count": res.data.count,
                                    "data": res.data.data
                                };
                            }
                            , cols: [[ //标题栏
                                { field: 'Id', title: 'ID', width: 80,totalRowText: '合计' }
                                , { field: 'DecPrice', title: '金额', Width: 60, totalRow: true }
                                , { field: 'CreateDate', title: '操作日期', width: 130 }
                                , { field: 'ActivityName', title: '业绩所属', width: 80 }
                                , { field: 'stateName', title: '状态', width: 80 }
                            ]]

                            , skin: 'line' //表格风格
                            , even: true
                            , page: true //是否显示分页

                            , limit: 5//每页默认显示的数量

                        });
                         table.on('tool(Linktable)', function (obj) {
                            var data = obj.data;
                            if (obj.event === 'detail') {
                                layer.msg('ID：' + data.id + ' 的查看操作');
                            } else if (obj.event === 'del') {
                                layer.confirm('真的删除行么', function (index) {

                                    DelLink(id,obj);
                                    layer.close(index);
                                });
                            } else if (obj.event === 'edit') {
                                layer.alert('编辑行：<br>' + JSON.stringify(data))
                            }
                        });


        });

    }
    function GetTable(id)
    {
                     var djUrl = "../Account/At/DjData";
                    var HtUrl = "../Account/At/RyHtData";
                    var HdUrl = "../Account/At/RyHdData";
                    layui.use('table', function () {
                        var table = layui.table;
                        table.render({
                            elem: '#Rydjtable'
                            , url: djUrl //数据接口
                            , where: { keyCode: "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id",Cid:id, t: new Date().getTime() }
                            , width: 580
                            , limit:5
                            , page: true //是否显示分页
                            , parseData: function (res) {
                                return {
                                    "code": res.code,
                                    "msg": res.message,
                                    "count": res.data.count,
                                    "data": res.data.data
                                };
                            }
                            , totalRow: true

                            , cols: [[ //标题栏
                                { field: 'FlowingName', title: '渠道', width: 80, totalRowText: '合计' }
                                , { field: 'ModeName', title: '流水类型', Width:130 }
                                , { field: 'Account', title: '金额', Width: 60, totalRow: true }
                                , { field: 'ADate', title: '操作日期', width: 130 }
                                , { field: 'AchName', title: '业绩所属', width: 80 }
                                , { field: 'stateName', title: '状态', width: 80 }
                            ]]

                            , skin: 'line' //表格风格
                            , even: true

                        });


                         table.render({
                             elem: '#Ryhttable'
                            , url: HtUrl //数据接口
                            , where: { keyCode: "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id",Cid:id, t: new Date().getTime() }
                             , width:1050
                             , totalRow: true
                             , parseData: function (res) {
                                 return {
                                     "code": res.code,
                                     "msg": res.message,
                                     "count": res.data.count,
                                     "data": res.data.data
                                 };
                             }
                            , cols: [[ //标题栏
                                { field: 'contractNumber', title: '合同编号' }
                                , { field: 'SetmealName', title: '套餐名称' }
                                , { field: 'je', title: '已收/实收/金额', width: 190 }
                                , { field: 'ConDate', title: '合同日期', width: 190 }
                                , { field: 'CourseDate', title: '执行日期' }
                                , { field: 'CreateDate', title: '创建日期', width: 110 }
                                , { field: 'AchName', title: '业绩所属' }
                                , { field: 'stateName', title: '合同状态' }
                                , { field: 'stateName', title: '收费状态' }
                            ]]

                            , skin: 'line' //表格风格
                            , even: true
                            , page: true //是否显示分页

                            , limit: 5//每页默认显示的数量

                        });

                        table.render({
                             elem: '#Ryhdtable'
                            , url: HdUrl //数据接口
                            , where: { keyCode:  "@ViewBag.keyCode", type: "@ViewBag.type", id: "@ViewBag.id",Cid:id, t: new Date().getTime() }
                            , width: 430
                            , totalRow: true
                            , parseData: function (res) {
                                return {
                                    "code": res.code,
                                    "msg": res.message,
                                    "count": res.data.count,
                                    "data": res.data.data
                                };
                            }
                            , cols: [[ //标题栏
                                { field: 'Id', title: 'ID', width: 80,totalRowText: '合计' }
                                , { field: 'DecPrice', title: '金额', Width: 60, totalRow: true }
                                , { field: 'CreateDate', title: '操作日期', width: 130 }
                                , { field: 'ActivityName', title: '业绩所属', width: 80 }
                                , { field: 'stateName', title: '状态', width: 80 }
                            ]]

                            , skin: 'line' //表格风格
                            , even: true
                            , page: true //是否显示分页

                            , limit: 5//每页默认显示的数量

                        });



                    });
    }
    function DelLink(id,obj) {
        $.ajax({
            url: "../Contract/ContractList/DelLink",
            dataType: "json",
            data: {
                type: "@ViewBag.type",
                id: id,
                keyCode: "@ViewBag.KeyCode",
                t: new Date().getTime()
            },
            success: function (data) {
                if (data.code == "0000") {
                    alert("删除成功");   obj.del();
                }
            }
        })
    }
    function IsContractNumber(Num) {

        $.ajax({
            url: "../Contract/ContractList/IsContractNumber",
            dataType: "json",
            data: {
                type: "@ViewBag.type",
                id: "@ViewBag.id",
                keyCode: "@ViewBag.KeyCode",
                ConNum: Num,
                t: new Date().getTime()
            },
            success: function (data) {
                if (data.code == "0000") {

                   $("#htsl").val(data.data[0].sl);

                }
            }
        });

    }

    function Do(id) {
        $.ajax({
            url: "../Contract/ContractList/DelImage",
            dataType: "json",
            data: {
                type: "@ViewBag.type",
                id:id,
                keyCode: "@ViewBag.KeyCode",
                t: new Date().getTime()
            },
            success: function (data) {
                if (data.code == "0000") {
                    alert("删除成功");
                    $('#ImageFj').html('');
                      $.ajax({
            url: "../Contract/ContractList/ContractImage",
            dataType: "json",
            data: {
                type: "@ViewBag.type",
                id: "@ViewBag.id",
                keyCode: "@ViewBag.KeyCode",
                t: new Date().getTime()
            },
            success: function (data) {
                if (data.code == "0000") {
                    var json = eval(data.data); //数组
                    if (json.length > 0) {
                        $('#ImageFj').append('<div class="layui-row layui-col-space15">')
                        for (var i = 0; i < json.length; i++) {
                            $('#ImageFj').append('<div class="layui-col-md4">  <div class="layui-card">');

                            $('#ImageFj').append('<img src="../UpFile/Contract' + json[i].ImageUrl + '" alt="#" width="300px" height="200px" class="layui-upload-img" style="padding:10px">');
                            if (json[i].zt == "0")
                                $('#ImageFj').append('<a href="#" onclick="javascript:Do(' + json[i].id + ');"><i class="layui-icon" style="color: #1E9FFF;">&#x1007;</i>  </a> ');
                            $('#ImageFj').append('</div></div>');
                        }
                        $('#ImageFj').append('</div>');
                    }
                }
            }
        })
                }
            }
        })
      }
</script>
@section fooler{
    <script>
if(@ViewBag.Customer>0)
    searchCus();


    if (@ViewBag.Lx== 1)
    {
        $("#Khry").html("@ViewBag.Khxx");
        $("#Khxx").css('display', '');

        GetHtTable(@ViewBag.data["Cid"],@ViewBag.id);

        $.ajax({
            url: "../Contract/ContractList/ContractImage",
            dataType: "json",
            data: {
                type: "@ViewBag.type",
                id: "@ViewBag.id",
                keyCode: "@ViewBag.KeyCode",
                t: new Date().getTime()
            },
            success: function (data) {
                if (data.code == "0000") {
                    var json = eval(data.data); //数组
                    if (json.length > 0) {
                        $('#ImageFj').append('<div class="layui-row layui-col-space15">')
                        for (var i = 0; i < json.length; i++) {
                            $('#ImageFj').append('<div class="layui-col-md4">  <div class="layui-card">');

                            $('#ImageFj').append('<img src="../UpFile/Contract' + json[i].ImageUrl + '" alt="#" width="300px" height="200px" class="layui-upload-img" style="padding:10px">');
                            if (json[i].zt == "0")
                                $('#ImageFj').append('<a href="#" onclick="javascript:Do(' + json[i].id + ');"><i class="layui-icon" style="color: #1E9FFF;">&#x1007;</i>  </a> ');
                            $('#ImageFj').append('</div></div>');
                        }
                        $('#ImageFj').append('</div>');
                    }
                }
            }
        })

    }

    </script>

}